import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useUserStore = defineStore('user', () => {
  // 状态
  const token = ref('')
  const userInfo = ref(null)
  
  // getters
  const isLogin = computed(() => !!token.value)
  
  // actions
  const login = async (credentials:{username:string, password:string}) => {
    // 这里应该是你的登录API调用
    // const res = await api.login(credentials)
    // token.value = res.token
    // userInfo.value = res.user
  }
  
  const logout = () => {
    token.value = ''
    userInfo.value = null
  }
  
  return {
    token,
    userInfo,
    isLogin,
    login,
    logout
  }
}, {
  persist: true // 启用持久化
})
